package cn.zbmao.web.services.impl;

import cn.zbmao.web.dao.SuccessfulNewsForUserDao;
import cn.zbmao.web.entity.TenderNews;
import cn.zbmao.web.services.SuccessfulServices;
import cn.zbmao.web.services.UserServices;
import cn.zbmao.web.util.DateUtil;
import cn.zbmao.web.util.dao.DaoFactory;
import com.jfinal.plugin.activerecord.Record;

import java.util.List;
import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 * User: huangzheng
 * Date: 2014/11/4
 * Time: 14:54
 * To change this template use File | Settings | File Templates.
 */
public abstract class abstractSuccessfulServices implements SuccessfulServices {
    protected static SuccessfulNewsForUserDao successfulNewsForUserDao = DaoFactory.getSuccessfulNewsForUserDao();

    /**
     * 初始化相关数据表数据
     * @param userId
     *
     */
    public void initNews(int userId){
        Map<String, List<Record>> map= UserServices.getUserInfo(userId);
        List<Record>district=map.get("user_district");
        List<Record>keyword=map.get("user_keyword");
        List<Record>qualification=map.get("user_qualification");
        if(district.size()>0) {
            if(keyword.size()>0 || qualification.size()>0){
                List<TenderNews> tenderNewsList = DaoFactory.getNewsDao().findSuccessfulNewsForUser(userId, DateUtil.getNowToIntDate(),map);
                successfulNewsForUserDao.delete(userId);
                successfulNewsForUserDao.save(tenderNewsList, userId);
            }

        }
    }




}
